package com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.db.DBLib;
import com.myuser.User;
import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;

public class UserDAO {
	public void addUser(User user){
		String sql = "insert into users(userName,pwd) values(?,?)";
		//获取连接
		Connection conn = DBLib.getConn();
		//创建数据库操作对象
		PreparedStatement pstmt;
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, user.getUserName());
			pstmt.setString(2, user.getPwd());
			//执行数据库操作
			pstmt.execute();
			pstmt.close();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			try {
				//关闭数据库连接
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	public ResultSet login(String userName) throws SQLException {
		String sql="select * from users where userName='"+userName+"'";
		Connection conn=DBLib.getConn();
		PreparedStatement pstmt=conn.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		return rs;
	}
}
